package com.jindy.module.project.service.impl;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.DateUtils;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.project.domain.Project;
import com.jindy.module.project.mapper.ProjectMapper;
import com.jindy.module.project.service.ProjectService;
import com.jindy.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 项目Service业务实现类
 *
 * @author zhaoxi
 * @date 2022-11-15
 */
@Service
public class ProjectServiceImpl  implements ProjectService {

    @Resource
    private ProjectMapper projectMapper;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询项目列表
     *
     * @param project 项目
     * @return 项目列表
     */
    @Override
    public List<Project> selectProjectList(Project project) {
        return projectMapper.selectProjectList(project);
    }

    /**
     * 查询项目
     *
     * @param id 项目主键
     * @return 项目数据
     */
    @Override
    public Project selectProjectById(String id) {
        return projectMapper.selectProjectById(id);
    }

    /**
     * 新增项目数据
     *
     * @param project 项目
     * @return 结果
     */
    @Override
    public int insertProject(Project project)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        project.setCreateBy(sysUser.getUserName());
        project.setCreateTime(DateUtils.getNowDate());
        return projectMapper.insertProject(project);
    }

    /**
     * 修改项目数据
     *
     * @param project
     * @return 结果
     */
    @Override
    public int updateProject(Project project) {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        project.setUpdateBy(sysUser.getUserName());
        project.setUpdateTime(DateUtils.getNowDate());
        return projectMapper.updateProject(project);
    }

    /**
     * 删除项目数据
     *
     * @param id 项目主键
     * @return 结果
     */
    @Override
    public int deleteProjectById(String id)
    {
        return projectMapper.deleteProjectById(id);
    }

    /**
     * 批量删除
     *
     * @param ids 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteProjectByIds(String[] ids)
    {
        return projectMapper.deleteProjectByIds(ids);
    }
}
